package br.ucb.cesbdao.janelas;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.TableRowSorter;

import lombok.Getter;
import lombok.Setter;

import org.apache.log4j.Logger;
import org.jdesktop.swingx.JXDatePicker;

import br.ucb.cesbdao.beans.DadosSessaoUser;
import br.ucb.cesbdao.beans.Trabalhador;
import br.ucb.cesbdao.controller.ControladorJanelas;
import br.ucb.cesbdao.enuns.EnumControleJanela;
import br.ucb.cesbdao.enuns.EnumErros;
import br.ucb.cesbdao.enuns.EnumFormatos;
import br.ucb.cesbdao.enuns.EnumLabelAndBotao;
import br.ucb.cesbdao.enuns.EnumResources;
import br.ucb.cesbdao.enuns.EnumTipoAtendimento;
import br.ucb.cesbdao.enuns.EnumTipoTrabalhador;
import br.ucb.cesbdao.enuns.EnumTitulo;
import br.ucb.cesbdao.model.AtendidoModel;
import br.ucb.cesbdao.model.AtendimentoModel;
import br.ucb.cesbdao.model.NaoAgendadoModel;
import br.ucb.cesbdao.model.PessoaModel;
import br.ucb.cesbdao.model.TrabalhadorModel;
import br.ucb.cesbdao.model.TrabalhadorPorGrupoModel;
import br.ucb.cesbdao.model.impl.AtendidoModelImpl;
import br.ucb.cesbdao.model.impl.AtendimentoModelImpl;
import br.ucb.cesbdao.model.impl.NaoAgendadoModelImpl;
import br.ucb.cesbdao.model.impl.PessoaModelImpl;
import br.ucb.cesbdao.model.impl.TrabalhadorModelImpl;
import br.ucb.cesbdao.model.impl.TrabalhadorPorGrupoModelImpl;
import br.ucb.cesbdao.modeloTabelas.ModeloTabelaAtendenteApoio;
import br.ucb.cesbdao.modeloTabelas.ModeloTabelaAtendimentoApoio;
import br.ucb.cesbdao.modeloTabelas.ModeloTabelaPacienteApoio;
import br.ucb.cesbdao.servicos.DateUtil;
import br.ucb.cesbdao.servicos.FocusTraversalOnArray;
import br.ucb.cesbdao.servicos.JanelaUtil;
import br.ucb.cesbdao.servicos.Servicos;
import br.ucb.cesbdao.servicos.Validadores;
import br.ucb.cesbdao.utilBeans.AtendimentoUtil;
import br.ucb.cesbdao.utilBeans.PessoaUtil;

@SuppressWarnings("serial")
public class JanelaApoio extends JFrame {
	private JTable tableAtendido;
	private JTable tableAFI;
	private JTable tableAtenidmento;
	private final ButtonGroup btGrupSexo = new ButtonGroup();
	private JLabel lblErroSexo;
	private JPanel contentPane;
	private JTextField txtNome;
	private JPanel panelNovaAtendimento;
	private JLabel lbNome;
	private JLabel lblSexo;
	private JLabel lblErroNome;
	private JRadioButton rdbtnMasculino;
	private JRadioButton rdbtnFeminino;
	private JButton btnNovoAtendimento;
	private JButton btnNovoAtendido;
	private JScrollPane scrollPaneAtendido;
	@SuppressWarnings("rawtypes")
	private JList listPreferencia;
	private JPanel panelSelectAFI;
	private JScrollPane scrollPaneAFI;
	private JPanel panelAtendimento;
	private JScrollPane scrollPaneAtendimento;
	private JPanel panelInformacao;
	private JLabel lblAfisEmAtendimento;
	private JLabel lblQtdafis;
	private JPanel panelRestam;
	private JLabel lblQtdRestam;
	private JLabel lblRestam;
	private JPanel panelNaoAgendadas;
	private JLabel lblPessoasAgendadas;
	private JPanel panelNext;
	private JLabel lblNextSenha;
	private JLabel lblNproxSenha;
	private JLabel lblNproxSenhaP;
	private JLabel lblNextSenhaP;
	private JPanel panelAfisAtendimento;
	ModeloTabelaPacienteApoio modeloTablePaciente = new ModeloTabelaPacienteApoio();
	ModeloTabelaAtendimentoApoio modeloTabelaAtendimento = new ModeloTabelaAtendimentoApoio();
	ModeloTabelaAtendenteApoio modeloTabelaTrabalhador = new ModeloTabelaAtendenteApoio();
	private final ButtonGroup btGrupFiltro = new ButtonGroup();
	private JRadioButton rdbtnTodos;
	private JRadioButton rdbtnDoDia;
	private JRadioButton rdbtnAtendendo;
	private JTextField txtNomeAFI;
	private JLabel lblNextSenhaE;
	private JLabel lblNproxSenhaE;
	private JRadioButton rdbtnOtaData;
	private JXDatePicker tfData;
	private JLabel lblNproxSenhaEs;
	private JLabel lblNexSenhaEs;
	private final ButtonGroup btGrupAtendimento = new ButtonGroup();
	private JRadioButton rdbtnHoje;
	private JPanel panelOpcMarcacao;
	@Getter @Setter
	private Trabalhador afi;
	private JLabel nomeAFI;
	private JLabel lblQnt_nAgd;
	private JPanel panel_1;
	private JPanel panel_2;
	private JPanel panel_3;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JRadioButton rdbtnDesistiram;
	private JRadioButton rdbtnAtendidos;
	private JRadioButton rdbtnNoAtendido;
	private JRadioButton rdbtnTodosAtendimentos;
	private JButton btnAlterna;
	static Logger logger = Servicos.carregaLog(JanelaApoio.class);
	/**
	 * Create the frame.
	 */
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public JanelaApoio() {
		final TrabalhadorModel trabModel = new TrabalhadorModelImpl();
		final AtendimentoModel atendModel = new AtendimentoModelImpl();
		final NaoAgendadoModel nAgenModel = new NaoAgendadoModelImpl();
		
		setTitle(EnumTitulo.TITULO_PRINCIPAL.getTitulo());
		setIconImage(Toolkit.getDefaultToolkit().getImage(JanelaApoio.class.getResource(EnumResources.ICONE_CESB.getCaminho())));
		ModeloTabelaAtendenteApoio.setFlag(true);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		addWindowListener(JanelaUtil.getInstance().janelaAdicionaWindowAdapter(this));
		setBounds(100, 100, 1024, 768);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		panelInformacao = new JPanel();
		panelInformacao.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));

		panelNovaAtendimento = new JPanel();
		panelNovaAtendimento.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), EnumTitulo.TITULO_NOVO_ATENDIDO.getTitulo(), TitledBorder.LEADING, TitledBorder.ABOVE_TOP, null, new Color(0, 0, 0)));

		panelSelectAFI = new JPanel();
		panelSelectAFI.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), EnumTitulo.TITULO_SELECT_AFI.getTitulo(), TitledBorder.LEADING, TitledBorder.ABOVE_TOP, null, new Color(0, 0, 0)));

		panelAtendimento = new JPanel();
		panelAtendimento.setBorder(new TitledBorder(null, EnumTitulo.TITULO_ATENDIMENTO.getTitulo(), TitledBorder.LEADING, TitledBorder.TOP, null, null));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
				gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
						.addComponent(panelSelectAFI, GroupLayout.PREFERRED_SIZE, 412, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.UNRELATED)
						.addComponent(panelNovaAtendimento, GroupLayout.PREFERRED_SIZE, 567, Short.MAX_VALUE)
						.addGap(7))
						.addGroup(gl_contentPane.createSequentialGroup()
								.addComponent(panelInformacao, GroupLayout.DEFAULT_SIZE, 988, Short.MAX_VALUE)
								.addContainerGap())
								.addGroup(gl_contentPane.createSequentialGroup()
										.addComponent(panelAtendimento, GroupLayout.DEFAULT_SIZE, 988, Short.MAX_VALUE)
										.addContainerGap())
				);
		gl_contentPane.setVerticalGroup(
				gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
						.addComponent(panelInformacao, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(panelSelectAFI, GroupLayout.PREFERRED_SIZE, 307, GroupLayout.PREFERRED_SIZE)
								.addComponent(panelNovaAtendimento, GroupLayout.PREFERRED_SIZE, 307, GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(ComponentPlacement.UNRELATED)
								.addComponent(panelAtendimento, GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE))
				);
		scrollPaneAtendimento = new JScrollPane();

		rdbtnHoje = new JRadioButton(EnumLabelAndBotao.HOJE.getTexto());
		rdbtnHoje.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabelaAtendimentoHoje();
			}
		});
		rdbtnHoje.setSelected(true);
		btGrupAtendimento.add(rdbtnHoje);

		rdbtnOtaData = new JRadioButton(EnumLabelAndBotao.DATA.getTexto());
		rdbtnOtaData.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tfData.setVisible(true);
				tableAtenidmento.setEnabled(false);
				tableAtenidmento.setBorder(new LineBorder(Color.RED));

			}
		});
		btGrupAtendimento.add(rdbtnOtaData);

		tfData = new JXDatePicker();
		tfData.getEditor().setText(EnumLabelAndBotao.SEM_TEXTO.getTexto());
		tfData.setVisible(false);
		tfData.getEditor().setEditable(false);
		tfData.setFormats(new String[] {EnumFormatos.DDMMYYYY.getFormato()});

		tfData.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(rdbtnOtaData.isSelected()){
					zeraPreencheTabelaBuscaAtendimento();
				}
			}
		});

		rdbtnTodosAtendimentos = new JRadioButton(EnumLabelAndBotao.TODOS.getTexto());
		rdbtnTodosAtendimentos.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				zeraPreencheTabelaAtendimento();

			}
		});
		rdbtnTodosAtendimentos.setSelected(true);
		buttonGroup.add(rdbtnTodosAtendimentos);

		rdbtnNoAtendido = new JRadioButton(EnumLabelAndBotao.NAO_ATENDIDO.getTexto());
		rdbtnNoAtendido.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				zeraPreencheTabelaAtendimento();

			}
		});
		buttonGroup.add(rdbtnNoAtendido);

		rdbtnAtendidos = new JRadioButton(EnumLabelAndBotao.ATENDIDOS.getTexto());
		rdbtnAtendidos.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				zeraPreencheTabelaAtendimento();

			}
		});
		buttonGroup.add(rdbtnAtendidos);
		
		rdbtnDesistiram = new JRadioButton(EnumLabelAndBotao.DESISTIRAM.getTexto());
		rdbtnDesistiram.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				zeraPreencheTabelaAtendimento();

			}
		});
		buttonGroup.add(rdbtnDesistiram);

		GroupLayout gl_panelAtendimento = new GroupLayout(panelAtendimento);
		gl_panelAtendimento.setHorizontalGroup(
			gl_panelAtendimento.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelAtendimento.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panelAtendimento.createParallelGroup(Alignment.LEADING)
						.addComponent(scrollPaneAtendimento, GroupLayout.DEFAULT_SIZE, 952, Short.MAX_VALUE)
						.addGroup(gl_panelAtendimento.createSequentialGroup()
							.addComponent(rdbtnHoje)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(rdbtnOtaData)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(tfData, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panelAtendimento.createSequentialGroup()
							.addComponent(rdbtnTodosAtendimentos)
							.addGap(18)
							.addComponent(rdbtnNoAtendido)
							.addGap(18)
							.addComponent(rdbtnAtendidos)
							.addGap(18)
							.addComponent(rdbtnDesistiram)))
					.addContainerGap())
		);
		gl_panelAtendimento.setVerticalGroup(
			gl_panelAtendimento.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panelAtendimento.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panelAtendimento.createParallelGroup(Alignment.BASELINE)
						.addComponent(rdbtnTodosAtendimentos)
						.addComponent(rdbtnNoAtendido)
						.addComponent(rdbtnAtendidos)
						.addComponent(rdbtnDesistiram))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPaneAtendimento, GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_panelAtendimento.createParallelGroup(Alignment.BASELINE)
						.addComponent(rdbtnHoje)
						.addComponent(rdbtnOtaData)
						.addComponent(tfData, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(15))
		);

		tableAtenidmento = new JTable();

		tableAtenidmento.setShowHorizontalLines(true);
		tableAtenidmento.setShowVerticalLines(true);
		tableAtenidmento.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				JanelaUtil.getInstance().janelaApoioRegistraAtendimento(tableAtenidmento,modeloTabelaAtendimento);
				zeraPreencheTabelaAtendimento();
				Servicos.preencheCabecario(lblQtdafis, lblQtdRestam, lblNproxSenha, lblNproxSenhaP, modeloTabelaAtendimento, modeloTabelaTrabalhador, lblNproxSenhaE, lblNproxSenhaEs, lblQnt_nAgd);
			}
		});
				
		scrollPaneAtendimento.setViewportView(tableAtenidmento);
		zeraPreencheTabelaAtendimento();
		panelAtendimento.setLayout(gl_panelAtendimento);

		scrollPaneAFI = new JScrollPane();

		rdbtnTodos = new JRadioButton(EnumLabelAndBotao.TODOS.getTexto());
		rdbtnTodos.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				zeraPreencheTabelaAFi();
			}
		});
		btGrupFiltro.add(rdbtnTodos);

		rdbtnDoDia = new JRadioButton(EnumLabelAndBotao.DO_DIA.getTexto());
		rdbtnDoDia.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				zeraPreencheTabelaAFi();
			}
		});
		btGrupFiltro.add(rdbtnDoDia);
		rdbtnDoDia.setSelected(true);

		rdbtnAtendendo = new JRadioButton(EnumLabelAndBotao.ATENDENDO.getTexto());
		rdbtnAtendendo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				zeraPreencheTabelaAFi();
			}
		});
		btGrupFiltro.add(rdbtnAtendendo);

		JLabel lblNomeAfi = new JLabel(EnumLabelAndBotao.FILTRAR_LISTAGEM.getTexto());

		txtNomeAFI = new JTextField();
		txtNomeAFI.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent arg0) {
				TableRowSorter<ModeloTabelaAtendenteApoio> sorter = new TableRowSorter<ModeloTabelaAtendenteApoio>(modeloTabelaTrabalhador);
				JanelaUtil.getInstance().filtrarTabela(txtNomeAFI.getText(), sorter,tableAFI, 0);
			}
		});
		txtNomeAFI.setColumns(10);

		JLabel lblApresentarAcimaOs = new JLabel(EnumLabelAndBotao.APRESENTAR_AFIS_ACIMA.getTexto());
		GroupLayout gl_panelSelectAFI = new GroupLayout(panelSelectAFI);
		gl_panelSelectAFI.setHorizontalGroup(
				gl_panelSelectAFI.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelSelectAFI.createSequentialGroup()
						.addContainerGap()
						.addGroup(gl_panelSelectAFI.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panelSelectAFI.createSequentialGroup()
										.addComponent(scrollPaneAFI, GroupLayout.PREFERRED_SIZE, 371, GroupLayout.PREFERRED_SIZE)
										.addContainerGap())
										.addGroup(gl_panelSelectAFI.createSequentialGroup()
												.addComponent(rdbtnAtendendo)
												.addPreferredGap(ComponentPlacement.UNRELATED)
												.addComponent(rdbtnDoDia)
												.addPreferredGap(ComponentPlacement.UNRELATED)
												.addComponent(rdbtnTodos)
												.addGap(18)
												.addComponent(txtNomeAFI, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
												.addGap(16))
												.addGroup(gl_panelSelectAFI.createSequentialGroup()
														.addComponent(lblApresentarAcimaOs)
														.addPreferredGap(ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
														.addComponent(lblNomeAfi)
														.addGap(37))))
				);
		gl_panelSelectAFI.setVerticalGroup(
				gl_panelSelectAFI.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panelSelectAFI.createSequentialGroup()
						.addContainerGap()
						.addComponent(scrollPaneAFI, GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addGroup(gl_panelSelectAFI.createParallelGroup(Alignment.LEADING)
								.addComponent(lblApresentarAcimaOs)
								.addComponent(lblNomeAfi))
								.addPreferredGap(ComponentPlacement.RELATED)
								.addGroup(gl_panelSelectAFI.createParallelGroup(Alignment.BASELINE)
										.addComponent(rdbtnAtendendo)
										.addComponent(rdbtnDoDia)
										.addComponent(rdbtnTodos)
										.addComponent(txtNomeAFI, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
										.addContainerGap())
				);

		tableAFI = new JTable();
		tableAFI.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				if(tableAFI.getSelectedColumn() == 1)
					zeraPreencheTabelaAFi();
				trabModel.qntAfisAtendimento(lblQtdafis, modeloTabelaTrabalhador);
			}
		});
		tableAFI.setModel(modeloTabelaTrabalhador);
		tableAFI.getColumnModel().getColumn(1).setPreferredWidth(100);
		scrollPaneAFI.setViewportView(tableAFI);
		zeraPreencheTabelaAFi();
		panelSelectAFI.setLayout(gl_panelSelectAFI);

		lbNome = new JLabel(EnumLabelAndBotao.NOME.getTexto());

		txtNome = new JTextField();
		txtNome.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent arg0) {
				txtNome.setText(txtNome.getText().toUpperCase());
				zeraPreencheTabelaPessoa();
				if(arg0.getKeyCode() == KeyEvent.VK_ENTER){
					cadastraPaciente();
				}

			}
		});


		txtNome.setToolTipText(EnumLabelAndBotao.INFORME_NOME.getTexto());
		txtNome.setColumns(10);

		rdbtnMasculino = new JRadioButton(EnumLabelAndBotao.MASCULINO.getTexto());
		btGrupSexo.add(rdbtnMasculino);

		rdbtnFeminino = new JRadioButton(EnumLabelAndBotao.FEMININO.getTexto());
		btGrupSexo.add(rdbtnFeminino);

		lblSexo = new JLabel(EnumLabelAndBotao.SEXO.getTexto());


		btnNovoAtendido = new JButton(EnumLabelAndBotao.NOVO_ATENDIDO.getTexto());
		btnNovoAtendido.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				cadastraPaciente();

			}
		});
		btnNovoAtendido.setIcon(new ImageIcon(JanelaApoio.class.getResource(EnumResources.ICONE_CADASTRAR_PEQUENO.getCaminho())));

		scrollPaneAtendido = new JScrollPane();

		lblErroNome = new JLabel(EnumLabelAndBotao.SEM_TEXTO.getTexto());
		lblErroNome.setForeground(Color.RED);
		lblErroNome.setFont(new Font(EnumFormatos.FONTE_COMIC.getFormato(), Font.BOLD, 10));

		lblErroSexo = new JLabel(EnumErros.ERRO_SEXO_VAZIO.getDescricao());
		lblErroSexo.setVisible(false);
		lblErroSexo.setForeground(Color.RED);
		lblErroSexo.setFont(new Font(EnumFormatos.FONTE_COMIC.getFormato(), Font.BOLD, 10));

		panelOpcMarcacao = new JPanel();
		panelOpcMarcacao.setBorder(new TitledBorder(null, EnumLabelAndBotao.SEM_TEXTO.getTexto(), TitledBorder.LEADING, TitledBorder.TOP, null, null));

		listPreferencia = new JList();
		listPreferencia.setModel(JanelaUtil.getInstance().criaModeloTipoAtendimento());
		listPreferencia.setBackground(SystemColor.control);
		listPreferencia.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), EnumTitulo.TITULO_TIPO.getTitulo(), TitledBorder.LEADING, TitledBorder.ABOVE_TOP, null, new Color(0, 0, 0)));


		btnNovoAtendimento = new JButton(EnumLabelAndBotao.SALVAR_ATENDIMENTO.getTexto());
		btnNovoAtendimento.setIcon(new ImageIcon(JanelaApoio.class.getResource(EnumResources.ICONE_CADASTRAR_PEQUENO.getCaminho())));
		btnNovoAtendimento.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(nomeAFI.getText().equalsIgnoreCase(EnumLabelAndBotao.SEM_TEXTO.getTexto())){
					if(AtendimentoUtil.novoAtendimentoChegada(tableAtendido,modeloTablePaciente,listPreferencia)){
						tabelaAtendimentoHoje();
						Servicos.preencheCabecario(lblQtdafis,lblQtdRestam,lblNproxSenha,lblNproxSenhaP,modeloTabelaAtendimento,modeloTabelaTrabalhador,lblNproxSenhaE,lblNproxSenhaEs, lblQnt_nAgd);
						rdbtnHoje.setSelected(true);
					}

				}else{
					if(AtendimentoUtil.novoAtendimentoChegada(tableAtendido,modeloTablePaciente,listPreferencia,getAfi().getId())){
						tabelaAtendimentoHoje();
						Servicos.preencheCabecario(lblQtdafis,lblQtdRestam,lblNproxSenha,lblNproxSenhaP,modeloTabelaAtendimento,modeloTabelaTrabalhador,lblNproxSenhaE,lblNproxSenhaEs, lblQnt_nAgd);
						nomeAFI.setText(EnumLabelAndBotao.SEM_TEXTO.getTexto());
						rdbtnHoje.setSelected(true);
					}
				}

			}
		});
		panelNovaAtendimento.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{txtNome, rdbtnMasculino, rdbtnFeminino, btnNovoAtendido, scrollPaneAtendido, tableAtendido, listPreferencia, btnNovoAtendimento, lblErroNome, lblErroSexo, lbNome, lblSexo}));

		JButton btnNewButton = new JButton(EnumLabelAndBotao.SELECIONAR_AFI.getTexto());
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ControladorJanelas.invokeJDialog(this.getClass().getSimpleName(), EnumControleJanela.JANELA_SELECIONA_AFI.getNomeJanela());
				if(SelecionaAFI.getTrabalhador() !=  null){
					setAfi(SelecionaAFI.getTrabalhador());
					String[] nome = getAfi().getNome().split(" ");
					nomeAFI.setText("AFI: "+nome[0]);
				}

			}
		});
		btnNewButton.setIcon(new ImageIcon(JanelaApoio.class.getResource(EnumResources.ICONE_SETA_CIMA.getCaminho())));

		nomeAFI = new JLabel(EnumLabelAndBotao.SEM_TEXTO.getTexto());
		nomeAFI.setFont(new Font(EnumFormatos.FONTE_TAHOMA.getFormato(), Font.PLAIN, 10));

		GroupLayout gl_panelOpcMarcacao = new GroupLayout(panelOpcMarcacao);
		gl_panelOpcMarcacao.setHorizontalGroup(
				gl_panelOpcMarcacao.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelOpcMarcacao.createSequentialGroup()
						.addContainerGap()
						.addGroup(gl_panelOpcMarcacao.createParallelGroup(Alignment.TRAILING)
								.addGroup(gl_panelOpcMarcacao.createSequentialGroup()
										.addComponent(listPreferencia, GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE)
										.addGap(31))
										.addGroup(gl_panelOpcMarcacao.createSequentialGroup()
												.addComponent(btnNewButton, GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
												.addGap(19))
												.addGroup(gl_panelOpcMarcacao.createSequentialGroup()
														.addComponent(nomeAFI)
														.addContainerGap(98, Short.MAX_VALUE))
														.addGroup(gl_panelOpcMarcacao.createSequentialGroup()
																.addComponent(btnNovoAtendimento, GroupLayout.PREFERRED_SIZE, 135, GroupLayout.PREFERRED_SIZE)
																.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
				);
		gl_panelOpcMarcacao.setVerticalGroup(
				gl_panelOpcMarcacao.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelOpcMarcacao.createSequentialGroup()
						.addComponent(listPreferencia)
						.addPreferredGap(ComponentPlacement.UNRELATED)
						.addComponent(btnNewButton)
						.addPreferredGap(ComponentPlacement.UNRELATED)
						.addComponent(nomeAFI)
						.addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(btnNovoAtendimento)
						.addGap(91))
				);
		panelOpcMarcacao.setLayout(gl_panelOpcMarcacao);

		tableAtendido = new JTable();

		tableAtendido.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

		scrollPaneAtendido.setViewportView(tableAtendido);
		GroupLayout gl_panelNovaAtendimento = new GroupLayout(panelNovaAtendimento);
		gl_panelNovaAtendimento.setHorizontalGroup(
			gl_panelNovaAtendimento.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
					.addGap(6)
					.addGroup(gl_panelNovaAtendimento.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
							.addGap(9)
							.addComponent(lbNome)
							.addGap(6)
							.addComponent(txtNome, GroupLayout.PREFERRED_SIZE, 211, GroupLayout.PREFERRED_SIZE)
							.addGap(1)
							.addComponent(lblErroNome))
						.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
							.addGap(16)
							.addComponent(lblSexo)
							.addGap(6)
							.addGroup(gl_panelNovaAtendimento.createParallelGroup(Alignment.LEADING)
								.addComponent(rdbtnMasculino)
								.addComponent(rdbtnFeminino))
							.addGap(12)
							.addComponent(btnNovoAtendido)
							.addGap(12)
							.addComponent(lblErroSexo))
						.addComponent(scrollPaneAtendido, GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panelOpcMarcacao, GroupLayout.PREFERRED_SIZE, 158, GroupLayout.PREFERRED_SIZE)
					.addContainerGap())
		);
		gl_panelNovaAtendimento.setVerticalGroup(
			gl_panelNovaAtendimento.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panelNovaAtendimento.createParallelGroup(Alignment.TRAILING)
						.addComponent(panelOpcMarcacao, GroupLayout.PREFERRED_SIZE, 258, GroupLayout.PREFERRED_SIZE)
						.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
							.addGroup(gl_panelNovaAtendimento.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
									.addGap(6)
									.addComponent(lbNome))
								.addComponent(txtNome, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
									.addGap(8)
									.addComponent(lblErroNome)))
							.addGap(12)
							.addGroup(gl_panelNovaAtendimento.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
									.addGap(7)
									.addComponent(lblSexo))
								.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
									.addGap(6)
									.addComponent(rdbtnMasculino)
									.addGap(6)
									.addComponent(rdbtnFeminino))
								.addComponent(btnNovoAtendido)
								.addGroup(gl_panelNovaAtendimento.createSequentialGroup()
									.addGap(33)
									.addComponent(lblErroSexo)))
							.addGap(21)
							.addComponent(scrollPaneAtendido, GroupLayout.PREFERRED_SIZE, 149, GroupLayout.PREFERRED_SIZE))))
		);
		panelNovaAtendimento.setLayout(gl_panelNovaAtendimento);

		panelAfisAtendimento = new JPanel();
		panelAfisAtendimento.setBackground(SystemColor.inactiveCaption);
		panelAfisAtendimento.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));

		panelRestam = new JPanel();
		panelRestam.setBackground(new Color(204, 204, 255));
		panelRestam.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));

		lblRestam = new JLabel(EnumLabelAndBotao.RESTAM.getTexto());
		lblRestam.setToolTipText(EnumLabelAndBotao.SEM_TEXTO.getTexto());

		lblQtdRestam = new JLabel();
		lblQtdRestam.setText(EnumLabelAndBotao.DOIS_ZEROS.getTexto());
		atendModel.qtdRestam(lblQtdRestam);
		lblQtdRestam.setFont(new Font(EnumFormatos.FONTE_TAHOMA.getFormato(), Font.PLAIN, 18));
		GroupLayout gl_panelRestam = new GroupLayout(panelRestam);
		gl_panelRestam.setHorizontalGroup(
				gl_panelRestam.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelRestam.createSequentialGroup()
						.addContainerGap()
						.addGroup(gl_panelRestam.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panelRestam.createSequentialGroup()
										.addGap(10)
										.addComponent(lblQtdRestam))
										.addComponent(lblRestam))
										.addContainerGap(11, Short.MAX_VALUE))
				);
		gl_panelRestam.setVerticalGroup(
				gl_panelRestam.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelRestam.createSequentialGroup()
						.addComponent(lblRestam)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(lblQtdRestam)
						.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				);
		panelRestam.setLayout(gl_panelRestam);

		panelNaoAgendadas = new JPanel();
		panelNaoAgendadas.setBackground(SystemColor.info);
		panelNaoAgendadas.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));

		lblPessoasAgendadas = new JLabel(EnumLabelAndBotao.PESSOAS_NAO_AGENDADAS.getTexto());

		JButton btnMarca = new JButton(EnumLabelAndBotao.MAIS.getTexto());
		btnMarca.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				lblQnt_nAgd.setText(nAgenModel.qtdNaoAgendados());
			}
		});

		lblQnt_nAgd = new JLabel(EnumLabelAndBotao.DOIS_ZEROS.getTexto());
		lblQnt_nAgd.setText(nAgenModel.qtdNaoAgendado());
		lblQnt_nAgd.setFont(new Font(EnumFormatos.FONTE_TAHOMA.getFormato(), Font.PLAIN, 18));

		JButton button = new JButton(EnumLabelAndBotao.MENOS.getTexto());
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				lblQnt_nAgd.setText(nAgenModel.retirarQtdNaoAgendados(lblQnt_nAgd.getText()));
			}
		});

		GroupLayout gl_panelNaoAgendadas = new GroupLayout(panelNaoAgendadas);
		gl_panelNaoAgendadas.setHorizontalGroup(
				gl_panelNaoAgendadas.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelNaoAgendadas.createSequentialGroup()
						.addContainerGap()
						.addGroup(gl_panelNaoAgendadas.createParallelGroup(Alignment.LEADING)
								.addComponent(lblPessoasAgendadas)
								.addGroup(gl_panelNaoAgendadas.createSequentialGroup()
										.addComponent(btnMarca)
										.addGap(18)
										.addComponent(lblQnt_nAgd)
										.addGap(18)
										.addComponent(button, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)))
										.addContainerGap(32, Short.MAX_VALUE))
				);
		gl_panelNaoAgendadas.setVerticalGroup(
				gl_panelNaoAgendadas.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelNaoAgendadas.createSequentialGroup()
						.addComponent(lblPessoasAgendadas)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addGroup(gl_panelNaoAgendadas.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblQnt_nAgd)
								.addComponent(button)
								.addComponent(btnMarca))
								.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				);
		panelNaoAgendadas.setLayout(gl_panelNaoAgendadas);

		panelNext = new JPanel();
		panelNext.setBackground(new Color(154, 205, 50));
		panelNext.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));

		JLabel lblProximasSenhas = new JLabel(EnumLabelAndBotao.PROXIMAS_SENHAS.getTexto());

		JPanel panel = new JPanel();
		panel.setBackground(new Color(154, 205, 50));
		panel.setBorder(new LineBorder(new Color(255, 255, 255), 1, true));

		lblNextSenha = new JLabel(EnumTipoAtendimento.NORMAL.getTipo());

		lblNproxSenha = new JLabel();
		lblNproxSenha.setText(EnumLabelAndBotao.TRES_ZEROS.getTexto());
		Servicos.proxSenha(lblNproxSenha,modeloTabelaAtendimento);
		lblNproxSenha.setFont(new Font(EnumFormatos.FONTE_TAHOMA.getFormato(), Font.PLAIN, 18));
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
				gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
						.addContainerGap()
						.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
								.addComponent(lblNproxSenha, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblNextSenha))
								.addContainerGap(17, Short.MAX_VALUE))
				);
		gl_panel.setVerticalGroup(
				gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
						.addComponent(lblNextSenha)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(lblNproxSenha)
						.addContainerGap(9, Short.MAX_VALUE))
				);
		panel.setLayout(gl_panel);

		panel_1 = new JPanel();
		panel_1.setBorder(new LineBorder(new Color(255, 255, 255), 1, true));
		panel_1.setBackground(new Color(154, 205, 50));

		lblNextSenhaP = new JLabel(EnumTipoAtendimento.PREFERENCIAL.getTipo());

		lblNproxSenhaP = new JLabel();
		lblNproxSenhaP.setText(EnumLabelAndBotao.TRES_ZEROS.getTexto());
		Servicos.proxSenhaP(lblNproxSenhaP,modeloTabelaAtendimento);
		lblNproxSenhaP.setFont(new Font(EnumFormatos.FONTE_TAHOMA.getFormato(), Font.PLAIN, 18));
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
				gl_panel_1.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panel_1.createSequentialGroup()
						.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNextSenhaP)
								.addGroup(gl_panel_1.createSequentialGroup()
										.addGap(14)
										.addComponent(lblNproxSenhaP, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)))
										.addContainerGap(5, Short.MAX_VALUE))
				);
		gl_panel_1.setVerticalGroup(
				gl_panel_1.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, gl_panel_1.createSequentialGroup()
						.addComponent(lblNextSenhaP, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(lblNproxSenhaP, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(9, Short.MAX_VALUE))
				);
		panel_1.setLayout(gl_panel_1);

		panel_2 = new JPanel();
		panel_2.setBorder(new LineBorder(new Color(255, 255, 255), 1, true));
		panel_2.setBackground(new Color(154, 205, 50));

		lblNextSenhaE = new JLabel(EnumTipoAtendimento.EMERGENCIAL.getTipo());

		lblNproxSenhaE = new JLabel();
		lblNproxSenhaE.setText(EnumLabelAndBotao.TRES_ZEROS.getTexto());
		Servicos.proxSenhaE(lblNproxSenhaE, modeloTabelaAtendimento);
		lblNproxSenhaE.setFont(new Font(EnumFormatos.FONTE_TAHOMA.getFormato(), Font.PLAIN, 18));
		GroupLayout gl_panel_2 = new GroupLayout(panel_2);
		gl_panel_2.setHorizontalGroup(
				gl_panel_2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_2.createSequentialGroup()
						.addContainerGap(7, Short.MAX_VALUE)
						.addGroup(gl_panel_2.createParallelGroup(Alignment.LEADING)
								.addGroup(Alignment.TRAILING, gl_panel_2.createSequentialGroup()
										.addComponent(lblNextSenhaE)
										.addContainerGap())
										.addGroup(Alignment.TRAILING, gl_panel_2.createSequentialGroup()
												.addComponent(lblNproxSenhaE, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
												.addGap(25))))
				);
		gl_panel_2.setVerticalGroup(
				gl_panel_2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_2.createSequentialGroup()
						.addComponent(lblNextSenhaE, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(lblNproxSenhaE, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(9, Short.MAX_VALUE))
				);
		panel_2.setLayout(gl_panel_2);

		panel_3 = new JPanel();
		panel_3.setBorder(new LineBorder(new Color(255, 255, 255), 1, true));
		panel_3.setBackground(new Color(154, 205, 50));

		lblNexSenhaEs = new JLabel(EnumTipoAtendimento.ESPECIFICO.getTipo());

		lblNproxSenhaEs = new JLabel();
		lblNproxSenhaEs.setText(EnumLabelAndBotao.TRES_ZEROS.getTexto());
		Servicos.proxSenhaEs(lblNproxSenhaEs, modeloTabelaAtendimento);
		lblNproxSenhaEs.setFont(new Font(EnumFormatos.FONTE_TAHOMA.getFormato(), Font.PLAIN, 18));
		GroupLayout gl_panel_3 = new GroupLayout(panel_3);
		gl_panel_3.setHorizontalGroup(
				gl_panel_3.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_panel_3.createSequentialGroup()
						.addContainerGap(16, Short.MAX_VALUE)
						.addGroup(gl_panel_3.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNproxSenhaEs, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblNexSenhaEs))
								.addGap(14))
				);
		gl_panel_3.setVerticalGroup(
				gl_panel_3.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_3.createSequentialGroup()
						.addComponent(lblNexSenhaEs, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(lblNproxSenhaEs, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(9, Short.MAX_VALUE))
				);
		panel_3.setLayout(gl_panel_3);
		GroupLayout gl_panelNext = new GroupLayout(panelNext);
		gl_panelNext.setHorizontalGroup(
				gl_panelNext.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelNext.createSequentialGroup()
						.addContainerGap()
						.addComponent(lblProximasSenhas)
						.addGap(13)
						.addComponent(panel, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_2, GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(panel_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addGap(21))
				);
		gl_panelNext.setVerticalGroup(
				gl_panelNext.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelNext.createSequentialGroup()
						.addGroup(gl_panelNext.createParallelGroup(Alignment.LEADING)
								.addComponent(panel, GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)
								.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
								.addComponent(panel_3, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
								.addComponent(panel_2, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
								.addGroup(Alignment.TRAILING, gl_panelNext.createSequentialGroup()
										.addContainerGap(34, Short.MAX_VALUE)
										.addComponent(lblProximasSenhas)))
										.addContainerGap())
				);
		panelNext.setLayout(gl_panelNext);
		
		btnAlterna = new JButton(EnumLabelAndBotao.SEM_TEXTO.getTexto());
		btnAlterna.setToolTipText(EnumLabelAndBotao.VOLTAR_GERENCIA.getTexto());
		if(!trabModel.consultaTrabalhadorByCpf(DadosSessaoUser.getInstance().getCPF()).getAcesso().equalsIgnoreCase(EnumTipoTrabalhador.GERENTE.getTipo())){
			btnAlterna.setVisible(false);
		}
		btnAlterna.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ControladorJanelas.invokeJFrame(this.getClass().getSimpleName(), EnumControleJanela.JANELA_PRINCIPAL.getNomeJanela());
				dispose();
			}
		});
		btnAlterna.setIcon(new ImageIcon(JanelaApoio.class.getResource(EnumResources.ICONE_SAIR.getCaminho())));
		GroupLayout gl_panelInformacao = new GroupLayout(panelInformacao);
		gl_panelInformacao.setHorizontalGroup(
			gl_panelInformacao.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelInformacao.createSequentialGroup()
					.addContainerGap()
					.addComponent(panelAfisAtendimento, GroupLayout.PREFERRED_SIZE, 134, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(panelRestam, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(panelNaoAgendadas, GroupLayout.PREFERRED_SIZE, 174, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(panelNext, GroupLayout.PREFERRED_SIZE, 430, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnAlterna)
					.addContainerGap(81, Short.MAX_VALUE))
		);
		gl_panelInformacao.setVerticalGroup(
			gl_panelInformacao.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, gl_panelInformacao.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panelInformacao.createParallelGroup(Alignment.LEADING)
						.addComponent(btnAlterna)
						.addComponent(panelNext, GroupLayout.PREFERRED_SIZE, 60, Short.MAX_VALUE)
						.addComponent(panelNaoAgendadas, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(panelRestam, GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
						.addComponent(panelAfisAtendimento, GroupLayout.PREFERRED_SIZE, 60, Short.MAX_VALUE))
					.addContainerGap())
		);

		lblAfisEmAtendimento = new JLabel(EnumLabelAndBotao.AFIS_ATENDIMENTO.getTexto());

		lblQtdafis = new JLabel();
		lblQtdafis.setText(EnumLabelAndBotao.DOIS_ZEROS.getTexto());
		trabModel.qntAfisAtendimento(lblQtdafis,modeloTabelaTrabalhador);
		lblQtdafis.setFont(new Font(EnumFormatos.FONTE_TAHOMA.getFormato(), Font.PLAIN, 18));
		GroupLayout gl_panelAfisAtendimento = new GroupLayout(panelAfisAtendimento);
		gl_panelAfisAtendimento.setHorizontalGroup(
				gl_panelAfisAtendimento.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelAfisAtendimento.createSequentialGroup()
						.addGroup(gl_panelAfisAtendimento.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panelAfisAtendimento.createSequentialGroup()
										.addContainerGap()
										.addComponent(lblAfisEmAtendimento))
										.addGroup(gl_panelAfisAtendimento.createSequentialGroup()
												.addGap(45)
												.addComponent(lblQtdafis)))
												.addContainerGap(15, Short.MAX_VALUE))
				);
		gl_panelAfisAtendimento.setVerticalGroup(
				gl_panelAfisAtendimento.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelAfisAtendimento.createSequentialGroup()
						.addComponent(lblAfisEmAtendimento)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(lblQtdafis)
						.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				);
		panelAfisAtendimento.setLayout(gl_panelAfisAtendimento);
		panelInformacao.setLayout(gl_panelInformacao);
		contentPane.setLayout(gl_contentPane);
	}

	public void cadastraPaciente(){
		boolean erro = false;
		if(!Validadores.validaString(EnumErros.ERRO_NOME_VAZIO.getDescricao(),txtNome,lblErroNome))
			erro = true;
		if(!Validadores.validaRadio(lblErroSexo, btGrupSexo))
			erro = true;
		if(!erro){
			PessoaModel model = new PessoaModelImpl();
			model.addPessoa(PessoaUtil.novaPessoa(txtNome.getText(),rdbtnMasculino.isSelected() ? 'M' : 'F'));
			zeraPreencheTabelaPessoa();
			Servicos.limpaCadastraAtendido(txtNome,btGrupSexo);
		}
	}


	/* **********************************************************************************************************************
	 * 													Tabelas
	 * 
	 ************************************************************************************************************************/
	public void zeraPreencheTabelaPessoa() {

		if(txtNome.getText().equalsIgnoreCase(EnumLabelAndBotao.SEM_TEXTO.getTexto())){
			modeloTablePaciente = new ModeloTabelaPacienteApoio();
			tableAtendido.setModel(modeloTablePaciente);
			return;
		}
		modeloTablePaciente = new ModeloTabelaPacienteApoio();
		tableAtendido.setModel(modeloTablePaciente);
		tableAtendido.getTableHeader().setReorderingAllowed(false);
		tableAtendido.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		tableAtendido.setAutoCreateRowSorter(true);
		AtendidoModel model = new AtendidoModelImpl();
		modeloTablePaciente.setPacientes(model.consultaPacienteByNome(txtNome.getText()));
		TableRowSorter<ModeloTabelaPacienteApoio> sorter = new TableRowSorter<ModeloTabelaPacienteApoio>(modeloTablePaciente);
		JanelaUtil.getInstance().filtrarTabela(txtNome.getText(), sorter,tableAtendido, 0);

	}
	public ArrayList<Trabalhador> filtraTabelaAFIDisponiveis(){
		TrabalhadorModel model = new TrabalhadorModelImpl();
		modeloTabelaTrabalhador.setTrabalhadors(model.consultaAllTrabalhadorByTipo(EnumTipoTrabalhador.AFI.getTipo()));
		return modeloTabelaTrabalhador.getTrabalhadorsAtendendo();
	}

	public void zeraPreencheTabelaBuscaAtendimento() {
		AtendimentoModel model = new AtendimentoModelImpl();
		modeloTabelaAtendimento = new ModeloTabelaAtendimentoApoio();

		tableAtenidmento.setModel(modeloTabelaAtendimento);
		tableAtenidmento.getTableHeader().setReorderingAllowed(false);
		tableAtenidmento.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

		tableAtenidmento.setAutoCreateRowSorter(true);
		modeloTabelaAtendimento.setAtendimento(model.getByData(tfData.getDate()));
	}
	public void zeraPreencheTabelaAtendimento() {

		modeloTabelaAtendimento = new ModeloTabelaAtendimentoApoio();
		tableAtenidmento.setModel(modeloTabelaAtendimento);
		tableAtenidmento.getTableHeader().setReorderingAllowed(false);
		tableAtenidmento.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		tableAtenidmento.setAutoCreateRowSorter(true);
		AtendimentoModel model = new AtendimentoModelImpl();
		if(rdbtnTodosAtendimentos.isSelected()){
			modeloTabelaAtendimento.setAtendimento(model.getByDataHoje());
		}else if(rdbtnNoAtendido.isSelected()){
			modeloTabelaAtendimento.setAtendimento(model.getEspera());
		}else if(rdbtnAtendidos.isSelected()){
			modeloTabelaAtendimento.setAtendimento(model.getEmAndamento());
		}else if(rdbtnDesistiram.isSelected()){
			modeloTabelaAtendimento.setAtendimento(model.getDesistentes());
		}
	}
	public void zeraPreencheTabelaAFi() {
		modeloTabelaTrabalhador = new ModeloTabelaAtendenteApoio();
		ModeloTabelaAtendenteApoio.setFlag(true);
		tableAFI.setModel(modeloTabelaTrabalhador);
		tableAFI.getTableHeader().setReorderingAllowed(false);
		tableAFI.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		tableAFI.setAutoCreateRowSorter(true);


		if(rdbtnTodos.isSelected()){
			TrabalhadorModel modelTrab = new TrabalhadorModelImpl();
			modeloTabelaTrabalhador.setTrabalhadors(modelTrab.consultaAllTrabalhadorByTipo(EnumTipoTrabalhador.AFI.getTipo()));
		}
		if(rdbtnDoDia.isSelected()){
			TrabalhadorPorGrupoModel model = new TrabalhadorPorGrupoModelImpl();
			modeloTabelaTrabalhador.setTrabalhadors(model.consultaTrabalhadorByDiaGrupo(DateUtil.getDiaSemanaAtualNum()));
		}
		if(rdbtnAtendendo.isSelected()){
			modeloTabelaTrabalhador.setTrabalhadors(filtraTabelaAFIDisponiveis());
		}
		tableAFI.getColumnModel().getColumn(1).setMaxWidth(90);
		tableAFI.getColumnModel().getColumn(1).setMinWidth(90);

	}
	public void tabelaAtendimentoHoje(){
		tableAtenidmento.setEnabled(true);
		tableAtenidmento.setBorder(null);
		zeraPreencheTabelaAtendimento();
		tfData.setVisible(false);
	}

	/*-------------------------------------------------------------------------------------------------------------
										Get's and Set's
--------------------------------------------------------------------------------------------------------------*/

	public String getLblQtdafis() {
		return lblQtdafis.getText();
	}

	public void setLblQtdafis(String Qtdafis) {
		lblQtdafis.setText(Qtdafis);
	}

	public String getLblQtdRestam() {
		return lblQtdRestam.getText();
	}

	public void setLblQtdRestam(String QtdRestam) {
		lblQtdRestam.setText(QtdRestam);
	}

	public String getLblNproxSenha() {
		return lblNproxSenha.getText();
	}

	public void setLblNproxSenha(String lblNproxSenha) {
		this.lblNproxSenha.setText(lblNproxSenha);
	}

	public String getLblNproxSenhaP() {
		return lblNproxSenhaP.getText();
	}

	public void setLblNproxSenhaP(String lblNproxSenhaP) {
		this.lblNproxSenhaP.setText(lblNproxSenhaP);
	}

}
